# coding: utf-8
import os
import sys

from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication
from loguru import logger
from qfluentwidgets import FluentTranslator

from common import cfg, init_create_table
from views import MainWindow

# 启用dpi刻度
if cfg.get(cfg.dpiScale) != "Auto":
    os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "0"
    os.environ["QT_SCALE_FACTOR"] = str(cfg.get(cfg.dpiScale))

logger.level('INFO')
logger.debug("创建应用")
# create application
init_create_table()

app = QApplication(sys.argv)
app.setAttribute(Qt.ApplicationAttribute.AA_DontCreateNativeWidgetSiblings)  # 禁止Qt自动创建兄弟窗口
logger.debug("设置语言")
locale = cfg.get(cfg.language).value
translator = FluentTranslator(locale)
app.installTranslator(translator)

# create main window
logger.debug("创建主窗口, 显示")
w = MainWindow()
w.show()
sys.exit(app.exec())
